from django.core.cache import cache
from django.http import HttpRequest

def setHostMiddleware(get_response):
    def middleware(request: HttpRequest):
        # 在这里设置全局变量
        cache.set('http_host', request.get_host())
        cache.set('http_scheme', request.scheme)

        response = get_response(request)

        return response

    return middleware